<?php
    session_start();
    
    // 로그인 상태 확인
    if(!isset($_SESSION['usernm'])){
        header("Location: login.php");
    }


?>

<!DOCTYPE html>
<html lang="ko"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>LifeQuest New Quest page</title> 
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />

<link rel="stylesheet" href="css/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="css/bootstrap-datepicker.css" type="text/css" />
<link rel="stylesheet" href="css/style.css" type="text/css" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script src="js/bootstrap.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="js/bootstrap-datepicker.kr.js"></script>
<script src="js/lifequest.js"></script>

<!--[if lt IE 9]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>  
<![endif]-->

<script type="text/javascript">
	
	$(document).ready(function() {
	    
	    // activate dropdown menu
		$(document).on('click','.dropdown-menu li a',function(){
		    var text = $(this).text();
		    $(this).closest('.dropdown').children('button.dropdown-toggle').text(text);
		    $(this).closest('.dropdown').children('button.dropdown-toggle').val($(this).attr("type"));
		    
		    if($(this).attr("type") == "d") {
		    	$("#quest_freq").text($("#div_quest_freq > ul > li:first > a").text());
		    	$("#quest_freq").val($("#div_quest_freq > ul > li:first > a").attr("type"));
		    	$("#quest_freq").addClass("disabled");
		    }	    
		    else {
		    	$("#quest_freq").removeClass("disabled");
		    }
		});
	    
	    $('#quest_exp_date').datepicker({
            language: 'kr'
        })
        .on('changeDate', function(e){
            var y = e.date.getFullYear(),
                _m = e.date.getMonth() + 1,
                m = (_m > 9 ? _m : '0'+_m),
                _d = e.date.getDate(),
                d = (_d > 9 ? _d : '0'+_d);
                
            // validate selected date!
                
            $(this).text(y + '-' + m + '-' + d);
            $(this).val(y + '-' + m + '-' + d);
            $(this).datepicker('hide');
        });
	    
		$("#btn_reg").click(function() {
		    $result = validate_input([$("#quest_name"), $("#quest_type"), $("#quest_freq")]);
		    
		    if($result) {
		        register_quest("<?php echo $_SESSION['userid'] ?>", $("#quest_name").val(), 
		                      $("#quest_type").val(), $("#quest_freq").val(), $("#quest_exp_date").val());
		    }
			     
		});
		
	});
	
	
	
</script>

</head>
<body>
	<div class="navbar ">
		<div class="navbar-inner">
			<div class="container">
				<a class="brand" href="./">Lifequest</a>
				<ul class="nav pull-right">
					<li class="dropdown">
						<a class="dropdown-toggle" data-toggle="dropdown">
							user : <?php echo $_SESSION['usernm'] ?>
							<b class="caret"></b>
						</a>
						<ul class="dropdown-menu">
							<li><a>user menu 1</a></li>
							<li><a>user menu 2</a></li>
						</ul>
					</li>
					<li>
						<a href="logout.php">Logout</a>		
					</li>
				</ul>
				
				
			</div>
		</div>    			
	</div>
    <div class="lq-container">
    	<div class="well">
	      	<div class="row-fluid">
	      	    <div class="control-group ">
    	      	    <div class="controls">
                        <input id="quest_name" class="span12" style="height:40px" type="text" placeholder="Quest 명을 입력하세요">
                        <!-- <span class="help-inline">Something may have gone wrong</span> -->
                    </div>
                </div>
	  			<!-- <input id="quest_name" class="span12" style="height:40px" type="text" placeholder="Quest 명을 입력하세요"> -->
	      		<div class="row-fluid" >
		            <div class="span4 control-group">
		                <div id="div_quest_type" class="btn-group dropdown">
		                    <button id="quest_type" class="btn dropdown-toggle" data-toggle="dropdown">간격 <span class="caret"></span></button>
		                    <ul class="dropdown-menu" role="menu">
		                        <li><a href="#" type="d">매일</a></li>
		                        <li><a href="#" type="w">매주</a></li>
		                        <li><a href="#" type="m">매월</a></li>
		                    </ul>
		                </div>
		            </div>
		            <div class="span4 control-group">
		                <div id="div_quest_freq" class="btn-group dropdown">
		                    <button id="quest_freq" class="btn dropdown-toggle" data-toggle="dropdown">횟수 <span class="caret"></span></button>
		                    <ul class="dropdown-menu" role="menu">
		                        <li><a href="#" type="1">1회</a></li>
		                        <li><a href="#" type="2">2회</a></li>
		                        <li><a href="#" type="3">3회</a></li>
		                        <li><a href="#" type="4">4회</a></li>
		                        <li><a href="#" type="4">5회</a></li>
		                    </ul>
		                </div>
		            </div>
		            <div class="span4 control-group">
		                <button id="quest_exp_date" class="btn btn-block" data-date-format="yyyy-mm-dd" >종료일</button>
		            </div>
	            </div>
	            <button id="btn_reg" class="btn btn-primary btn-large btn-block" style="margin-top: 10px" >Register</button>
	        </div>
        </div>
    </div>
    
</body>
</html>